package net.towee.client.managers;

import net.towee.client.event.core.BoardCreatedEvent;
import net.towee.client.event.core.BoardRemovedEvent;
import net.towee.client.event.core.BoardRenamedEvent;
import net.towee.client.event.core.GadgetAttached;
import net.towee.client.event.core.GroupAttachedToBoardEvent;
import net.towee.client.event.core.GroupDetachedFromBoardEvent;
import net.towee.model.account.Board;
import net.towee.model.account.Gadget;
import net.towee.model.group.GroupIdentity;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * Manage boards of logged in user. Implementation must initialize in the
 * GadgetsHolder all available gadgets.
 * 
 * @author c58
 */
public interface DashBoardManager {
	/**
	 * Add new board to account. It generate id, set it in board and invoke
	 * success method in handler.
	 * 
	 * On success it fire an event {@link BoardCreatedEvent}
	 * 
	 * @param board
	 */
	void addBoard(Board board, AsyncCallback<Board> handler);

	/**
	 * Remove board with given id.
	 * 
	 * On success it fire an event {@link BoardRemovedEvent}
	 * 
	 * @param boardId
	 */
	void removeBoard(String boardId, AsyncCallback<Boolean> handler);

	/**
	 * Rename board with given id.
	 * 
	 * On success it fire an event {@link BoardRenamedEvent}
	 * 
	 * @param boardId
	 * @param newName
	 */
	void renameBoard(String boardId, String newName, AsyncCallback<Boolean> handler);

	/**
	 * Attach new group to board with given id
	 * 
	 * On success it fire an event {@link GroupAttachedToBoardEvent}
	 * 
	 * @param boardId
	 * @param groupId
	 */
	void attachGroupToBoard(String boardId, String groupId, AsyncCallback<GroupIdentity> handler);

	/**
	 * Detach group from board
	 * 
	 * On success it fire an event {@link GroupDetachedFromBoardEvent}
	 * 
	 * @param boardId
	 * @param groupId
	 */
	void detachGroupFromBoard(String boardId, String groupId, AsyncCallback<Boolean> handler);

	/**
	 * Attach new gadget to given board. It generate id for gadget, attach it to
	 * local soterd account data and invoke handler.
	 * 
	 * On success it fire an event {@link GadgetAttached}
	 * 
	 * @param boardId
	 * @param g
	 * @param handler
	 */
	void attachGadgetToBoard(String boardId, Gadget g, AsyncCallback<Gadget> handler);

	/**
	 * Detach given gadget from some board.
	 * 
	 * On success it fire an event {@link GadgetDetached}
	 * 
	 * @param boardId
	 * @param gadgetId
	 * @param handler
	 */
	void detachGadgetFromBoard(String boardId, String gadgetId, AsyncCallback<Boolean> handler);

	/**
	 * Save given gadget in some board. Given gadget MUST be attached to board
	 * and have id and name.
	 * 
	 * On success it fire an event {@link GadgetSaved}
	 * 
	 * @param boardId
	 * @param g
	 * @param handler
	 */
	void saveGadget(String boardId, Gadget g, AsyncCallback<Boolean> handler);

	void updateBoard(Board currentBoard, AsyncCallback<Board> callback);
}